package com.wcj.test;

/**
 * 请实现无重复数字的升序数组的二分查找
 */
public class 二分查找I {

    public int search (int[] nums, int target) {
        if (nums.length == 0){
            return -1;
        }
        int mid = nums.length/2;
        int left = 0;
        int right = nums.length;
        while (left <= right){
            mid = left + (right-left)/2;
            if (nums[mid] == target){
                return mid;
            }else if (nums[mid] < target){
                left = mid + 1;
            }else {
                right = mid - 1;
            }
        }
        return -1;
    }
}
